<?php
namespace App\Http\Requests\Seek;

use App\Http\Requests\Request;
use Illuminate\Validation\Rule;

class PostRequest extends Request {

    public function rules():array
    {
        return [
            'uid' => 'required|numeric',
            'prov' => 'required|numeric',
            'city' => 'required|numeric',
            'area' => 'required|numeric',
            'address' => 'required',
            'lon' => 'required|numeric',
            'lat' => 'required|numeric',
            'date' => 'required|date',
            'title' => 'between:0,85',
            'name' => 'required|between:1,20',
            'sex' => [
                Rule::in([0,1])
            ],
            'age' => "digits_between:1,120",
            'contact_name' => 'required|between:1,20',
            'contact_mobile' => [
                "required_without_all:contact_qqorwechat",
                "regex:/^1[3456789]\d{9}$/",
                "nullable"
            ],
            'contact_qqorwechat' => [
                "required_without_all:contact_mobile",
                "regex:/^[0-9a-zA-Z_-]$/",
                "nullable"
            ],
            'imgArr' => "required|array"
        ];
    }

    public function messages():array
    {
        return [
            'uid.required' => '参数错误,校验失败',
            'uid.numeric' => '参数格式错误',
            'prov.required' => '省市区必填',
            'prov.numeric' => '省市区格式错误',
            'city.required' => '省市区必填',
            'city.numeric' => '省市区格式错误',
            'area.required' => '省市区必填',
            'area.numeric' => '省市区格式错误',
            'address.required' => '请选择丢失人失踪大致位置',
            'lon.required' => '经纬度必须',
            'lon.numeric' => '经纬度格式错误',
            'lat.required' => '经纬度必须',
            'lat.numeric' => '经纬度格式错误',
            'date.required' => '请选择大致丢失日期',
            'date.date' => '日期格式错误',
            'title.between' => '标题长度错误',
            'name.required' => '姓名必须',
            'name.between' => '姓名长度错误',
            'sex.in' => '性别范围错误',
            'age.digits_between' => '年龄范围错误',
            'contact_name.required' => '联系人姓名必须',
            'contact_name.between' => '联系人姓名长度错误',
            'contact_mobile.required_without_all' => '联系人电话qq或微信必填一项',
            'contact_mobile.regex' => '联系人电话格式错误!请填写中国大陆号码',
            'contact_qqorwechat.required_without_all' => '联系人电话qq或微信必填一项',
            'contact_qqorwechat.regex' => 'qq或微信格式错误',
            'imgArr.required' => '必须选择一张图片',
            'imgArr.array' => '图片格式错误',
        ]; // TODO: Change the autogenerated stub
    }

}